package graduation.claf.controller;

import graduation.claf.pojo.Record;
import graduation.claf.service.ifs.IRecordService;
import graduation.claf.tools.ResponseCode;
import graduation.claf.utils.ServerResponse;
import graduation.claf.vo.StatisticInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

@RestController
@RequestMapping(value = "/portal")
public class StatisticController {

    @Autowired
    IRecordService recordService;

    //分时段求和统计
    @PostMapping(value = "/SumStatistic.do")
    public ServerResponse statisticWithSummation(String bookId){
        List<StatisticInfo> statisticInfos = new ArrayList<>();
        for (int i=0;i<4;i++){
            StatisticInfo newStatistic = recordService.SumStatistic(bookId,i);
            if (newStatistic == null)
                return ServerResponse.createServerResponseByFail(
                        ResponseCode.PARAMETER_ERROR.getCode(),
                        ResponseCode.PARAMETER_ERROR.getMsg());
            statisticInfos.add(newStatistic);
        }
        return ServerResponse.createServerResponseBySuccess(statisticInfos);
    }

    //分时段明细
    //type 时段
    @PostMapping(value = "/detailStatistic.do")
    public ServerResponse detailStatistic(String bookId,int timeZoneType){
//        Calendar start = Calendar.getInstance();
//        Calendar end = Calendar.getInstance();
//        constructIntervalOfDate(start,end,timeZoneType);
//        List<Record> records = recordService.Details(bookId,timeZoneType);
//        if (records == null) return ServerResponse.createServerResponseByFail(ResponseCode.PARAMETER_ERROR.getCode(),ResponseCode.PARAMETER_ERROR.getMsg());
//        return ServerResponse.createServerResponseBySuccess(records);
        return null;
    }

    //消费分类统计
    //type 收入/支出
    @PostMapping(value = "/classifiedStatistics.do")
    public ServerResponse classifiedStatistics(String bookId,int timeZoneType){
        return recordService.classifiedStatistic(bookId,timeZoneType);
    }

    //流水统计
    @PostMapping(value = "/flowStatistics.do")
    public ServerResponse flowStatistics(String bookId,int timeZoneType){
        return recordService.flowStatistic(bookId,timeZoneType);
    }

}
